﻿// Copyright 2009 Mike Geise
// 
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// 
//     http://www.apache.org/licenses/LICENSE-2.0
// 
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

namespace Falcon.Core.Domain.Values
{
	using System;
	using System.Web.Mvc;
	using Falcon.Core.Domain.Enums;
	using Falcon.Core.Extensions;
	using Falcon.Core.Validation;

	public class UserGroupUpdate : ValueBase<UserGroupUpdate>
	{
		/// <summary>
		/// Initializes a new instance of the <see cref="UserGroupUpdate"/> class.
		/// </summary>
		public UserGroupUpdate()
		{
			
		}

		/// <summary>
		/// Initializes a new instance of the <see cref="UserGroupUpdate"/> class.
		/// </summary>
		/// <param name="group">The group.</param>
		public UserGroupUpdate(UserGroup group) 
			: this()
		{
			this.Id = group.Id;
			this.Title = group.Title;
			this.Body = group.Body;
			this.IsAlbumsEnabled = group.IsAlbumsEnabled;
			this.IsCommentsEnabled = group.IsCommentsEnabled;
			this.IsHidden = group.IsHidden;
			this.Scope = group.Scope;
		}

		/// <summary>
		/// Gets or sets the id.
		/// </summary>
		/// <value>The id.</value>
		public int Id
		{
			get; 
			set;
		}

		/// <summary>
		/// Gets or sets the title.
		/// </summary>
		/// <value>The title.</value>
		public string Title
		{
			get;
			set;
		}

		/// <summary>
		/// Gets or sets the body.
		/// </summary>
		/// <value>The body.</value>
		public string Body
		{
			get;
			set;
		}

		/// <summary>
		/// Gets or sets a value indicating whether this instance is albums enabled.
		/// </summary>
		/// <value>
		/// 	<c>true</c> if this instance is albums enabled; otherwise, <c>false</c>.
		/// </value>
		public bool IsAlbumsEnabled
		{
			get;
			set;
		}

		/// <summary>
		/// Gets or sets a value indicating whether this instance is comments enabled.
		/// </summary>
		/// <value>
		/// 	<c>true</c> if this instance is comments enabled; otherwise, <c>false</c>.
		/// </value>
		public bool IsCommentsEnabled
		{
			get;
			set;
		}

		/// <summary>
		/// Gets or sets a value indicating whether this instance is hidden.
		/// </summary>
		/// <value><c>true</c> if this instance is hidden; otherwise, <c>false</c>.</value>
		public bool IsHidden
		{
			get;
			set;
		}

		/// <summary>
		/// Gets or sets the scope.
		/// </summary>
		/// <value>The scope.</value>
		public UserGroupScope Scope
		{
			get;
			set;
		}

		/// <summary>
		/// Gets the scopes.
		/// </summary>
		/// <value>The scopes.</value>
		public SelectList Scopes
		{
			get
			{
				return new SelectList(Enum.GetNames(typeof(UserGroupScope)), this.Scope);
			}
		}

		/// <summary>
		/// Validation rules for this instance.
		/// </summary>
		/// <returns></returns>
		public override Validator<UserGroupUpdate> Rules()
		{
			var rules = base.Rules();

			rules.Add(x => x.Title)
				.NotEmpty(Resources.Errors.Required.Fmt(Resources.Titles.Title));

			return rules;
		}

		/// <summary>
		/// Validates this instance.
		/// </summary>
		public override void Validate()
		{
			this.Rules().Validate(this);
		}
	}
}